package controller;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import core.PgSQL;
import core.View;
import model.*;

public class UserGroupList extends HttpServlet {
	private static final long serialVersionUID = 1L;
	PgSQL db = PgSQL.getInstance();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ArrayList<UserGroup> grouplist = new ArrayList<UserGroup>();
		
		try{
			ResultSet rs = db.query("SELECT * FROM qz_usergroup");
			while(rs.next()){
				UserGroup group = new UserGroup();
				group.setGroupId(rs.getInt(1));
				group.setGroupName(rs.getString(2));
				group.setPermission(rs.getInt(3));
				grouplist.add(group);
			}
			request.setAttribute("grouplist[]", grouplist.toArray());
			
			View.show(request, response, "usergroup_list");
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
